package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.util.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "属性表接口")
public class BaseAttrInfoController {
    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    //新增平台属性包含属性值 关联到某个分类下
    @PostMapping("/saveAttrInfo")
    @ApiOperation("保存平台属性")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation("根据平台属性Id 获取到平台属性值集合")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable Long attrId){
        //根据属性Id获取平台属性对象
        BaseAttrInfo baseAttrInfo = baseAttrInfoService.getAttrInfo(attrId);
        //再从平台属性对象中取出平台属性值集合
        List<BaseAttrValue> list = baseAttrInfo.getAttrValueList();
        return Result.ok(list);
    }


}
